package com.SouthernWall_404.age_tool.common.API.NBT;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MusicBlockHandler {


    private static final String MUSIC_PATH="music_path";
    private static final String RADIUS="radius";
    private static final Logger log = LoggerFactory.getLogger(MusicBlockHandler.class);

    /*
    用于获取到方块实体内的blockEntity
    中储存的本模组信息
    如没有，新建
     */
//    public static CompoundTag getOrCreateModPackBE(BlockEntity blockEntity)
//    {
//        CompoundTag nbt;
//
//        if(blockEntity.getLevel().isClientSide)//如果是客户端
//        {
////            ModChannels.sendToServer(new MusicBlockInitHandShakePacket(blockEntity.getBlockPos()));
////
////            CompoundTag modPack= MusicBlockClientInitHandler.read(blockEntity.getBlockPos());
//
////            return modPack;
//
//        }
//
//        nbt=blockEntity.serializeNBT();
//
//
//        if(nbt==null)
//        {
//            return new CompoundTag();
//        }
//        CompoundTag ModPack=(CompoundTag) nbt.get(AgeTool.MODID);
//        if(ModPack==null)
//        {
//            ModPack=new CompoundTag();
//        }
////        Minecraft.getInstance().player.sendSystemMessage(Component.literal(""+nbt+","+blockEntity.getLevel()));
//        return ModPack;
//    }
//    /*
//    用于为blockEntity写入模组数据包
//    需要写好的模组数据包
//     */
//    public static void putModPackBE(BlockEntity blockEntity,CompoundTag ModPack)
//    {
//        MusicBlockEntity musicBlockEntity=(MusicBlockEntity)blockEntity;
//
//        musicBlockEntity.setNBT(ModPack);
//
//
//        BlockPos blockPos=blockEntity.getBlockPos();
//        ModChannels.sendToServer(new MusicBlockPacket(ModPack,blockPos));
//    }

    //用于获取musicBlock中存储的设定
    public static MusicBlockInfo getMusicBlockSetting(CompoundTag ModPack)
    {
        MusicBlockInfo musicBlockInfo =new MusicBlockInfo();
        musicBlockInfo.musicLocation=new ResourceLocation(ModPack.getString(MUSIC_PATH));
        musicBlockInfo.radius=ModPack.getInt(RADIUS);

        return musicBlockInfo;
    }

//    public static MusicBlockInfo getMusicBlockSetting(BlockEntity blockEntity)
//    {
//        CompoundTag ModPack=getOrCreateModPackBE(blockEntity);
//        return getMusicBlockSetting(ModPack);
//    }


//    //用于重设musicBlock中的存储的设定
//    public static void setMusicBlockSetting(ResourceLocation musicLocation,BlockEntity musicBlockEntity)
//    {
//
//        MusicBlockEntity blockEntity=(MusicBlockEntity)musicBlockEntity;
//        CompoundTag modPack=new CompoundTag();
//        modPack.putString(MUSIC_PATH,musicLocation.toString());
//        blockEntity.putModPackBE(modPack);
//    }



}
